package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.mapper.MemberMapper;
import com.itheima.mapper.OrderMapper;
import com.itheima.mapper.SetMealMapper;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import com.mysql.jdbc.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @Description 预约服务接口实现类
 * @Author makun
 * @Date 2023/9/23 14:54
 * @Version 1.0
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Override
    public Page<Order> findPage(QueryPageBean queryPageBean) {
        // 查询条件
        HashMap<String, Object> queryCondition = new HashMap<>();
        String queryString = queryPageBean.getQueryString();
        if (!StringUtils.isNullOrEmpty(queryString)) {
            queryCondition.put("fileNumber", queryString);
            queryCondition.put("name", queryString);
            queryCondition.put("phoneNumber", queryString);
        }
        // 分页条件
        Page<Order> orderPage = new Page<>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        baseMapper.selectDetailPage(orderPage, queryCondition);
        // 执行查询
        return orderPage;
    }

    @Override
    public boolean hasVisit(Integer id) {
        return baseMapper.updateById(new Order(id, null, null, null, Order.ORDERSTATUS_YES, null, null, null)) == 1;
    }

    @Override
    public boolean delete(Integer id) {
        return baseMapper.deleteById(id) == 1;
    }
}
